package com.shtel.bss.saas.tenant.controller;

import com.shtel.bss.saas.core.base.exception.ExceptionBuilder;
import com.shtel.bss.saas.tenant.dto.SysUserDTO;
import com.shtel.bss.saas.tenant.enums.SysExceptionCode;
import com.shtel.bss.saas.tenant.mapstrut.EntityDtoMapper;
import com.shtel.bss.saas.tenant.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("bam/login")
public class LoginController {

    @Autowired
    private ISysUserService sysUserService;

    @GetMapping
    private SysUserDTO login(@RequestParam("account") String account, @RequestParam("password") String password){
        if(StringUtils.isEmpty(account)){
            throw ExceptionBuilder.paramsException(SysExceptionCode.PARAM_IS_NULL,"用户名为空");
        }
        if(StringUtils.isEmpty(password)){
            throw ExceptionBuilder.paramsException(SysExceptionCode.PARAM_IS_NULL,"密码为空");
        }
        return EntityDtoMapper.INSTANCE.toSysUserDTO(sysUserService.login(account,password));
    }
}
